<?php
$themename = "imagine";
$shortname = "imagine";
$options = array (
	array(	"name" => "Thank you for using this theme!",
			"type" => "title"),
	array(	"type" => "open"),
	array(	"name" => "rss_url",
			"desc" => "Enter your rss url.",
			"id" => $shortname."_rss_url",
			"std" => "",
			"type" => "text"),
	array(	"name" => "emailrss_url",
			"desc" => "Enter your email rss url.",
			"id" => $shortname."_emailrss_url",
			"std" => "",
			"type" => "text"),
	array(	"name" => "wap_url",
			"desc" => "Enter your wap url",
			"id" => $shortname."_wap_url",
			"std" => "",
			"type" => "text"),
	array(	"name" => "twitter_url",
			"desc" => "Enter your twitter url.",
			"id" => $shortname."_twitter_url",
			"std" => "",
			"type" => "text"),
	array(	"name" => "About",
			"desc" => "Text to display as about description.(HTML enabled)",
            "id" => $shortname."_about",
            "type" => "textarea"),
	array(	"name" => "Email for Gravatar",
			"desc" => "Enter your email to display your gravatar.",
			"id" => $shortname."_efg",
			"std" => "",
			"type" => "text"),
	array(  "name" => "Display Gravatar?",
			"desc" => "Check this box if you would like to display gravatar with about description",
            "id" => $shortname."_gravatar",
            "type" => "checkbox",
            "std" => "false"),
	array(	"type" => "close")
);
function mytheme_add_admin() {
    global $themename, $shortname, $options;
    if ( $_GET['page'] == basename(__FILE__) ) {
        if ( 'save' == $_REQUEST['action'] ) {
                foreach ($options as $value) {
                    update_option( $value['id'], $_REQUEST[ $value['id'] ] ); }
                foreach ($options as $value) {
                    if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ]  ); } else { delete_option( $value['id'] ); } }
                header("Location: themes.php?page=functions.php&saved=true");
                die;
        } else if( 'reset' == $_REQUEST['action'] ) {
            foreach ($options as $value) {
                delete_option( $value['id'] ); }
            header("Location: themes.php?page=functions.php&reset=true");
            die;
        }
    }
    add_theme_page($themename." Options", "".$themename." Options", 'edit_themes', basename(__FILE__), 'mytheme_admin');
}function mytheme_admin() {
    global $themename, $shortname, $options;
    if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings saved.</strong></p></div>';
    if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings reset.</strong></p></div>';
    
?>
<div class="wrap">
<h2><?php echo $themename; ?> settings</h2>
<form method="post">
<?php foreach ($options as $value) { 
	switch ( $value['type'] ) {
			case "open":
		?>
        <table width="100%" border="0" style="background-color:#eef5fb; padding:10px;">
		<?php break;
		case "close":
		?>
        </table><br />
		<?php break;
		case "title":
		?>
		<table width="100%" border="0" style="background-color:#dceefc; padding:5px 10px;"><tr>
        	<td colspan="2"><h3 style="font-family:Georgia,'Times New Roman',Times,serif;"><?php echo $value['name']; ?> - <a href="http://paranimage.com" title="<?php _e('I am the key to the lock in your house.','paranimage') ?>"><?php _e('Paranimage','paranimage') ?></a></h3></td>
        </tr>
		<?php break;
		case 'text':
		?>
        <tr>
            <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
            <td width="80%"><input style="width:400px;" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" value="<?php if ( get_settings( $value['id'] ) != "") { echo get_settings( $value['id'] ); } else { echo $value['std']; } ?>" /></td>
        </tr>
        <tr>
            <td><small><?php echo $value['desc']; ?></small></td>
        </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;">&nbsp;</td></tr><tr><td colspan="2">&nbsp;</td></tr>
		<?php 
		break;
		case 'textarea':
		?>
        <tr>
            <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
            <td width="80%"><textarea name="<?php echo $value['id']; ?>" style="width:400px; height:200px;" type="<?php echo $value['type']; ?>" cols="" rows=""><?php if ( get_settings( $value['id'] ) != "") { echo stripslashes(get_settings( $value['id'] )); } else { echo $value['std']; } ?></textarea></td>
            
        </tr>
        <tr>
            <td><small><?php echo $value['desc']; ?></small></td>
        </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;">&nbsp;</td></tr><tr><td colspan="2">&nbsp;</td></tr>
		<?php 
		break;
		case 'select':
		?>
        <tr>
            <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
            <td width="80%"><select style="width:240px;" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>"><?php foreach ($value['options'] as $option) { ?><option<?php if ( get_settings( $value['id'] ) == $option) { echo ' selected="selected"'; } elseif ($option == $value['std']) { echo ' selected="selected"'; } ?>><?php echo $option; ?></option><?php } ?></select></td>
       </tr>  
       <tr>
            <td><small><?php echo $value['desc']; ?></small></td>
       </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;">&nbsp;</td></tr><tr><td colspan="2">&nbsp;</td></tr>
		<?php
        break;
		case "checkbox":
		?>
            <tr>
            <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
                <td width="80%"><? if(get_settings($value['id'])){ $checked = "checked=\"checked\""; }else{ $checked = ""; } ?>
                        <input type="checkbox" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" value="true" <?php echo $checked; ?> />
                        </td>
            </tr>
                        
            <tr>
                <td><small><?php echo $value['desc']; ?></small></td>
           </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;">&nbsp;</td></tr><tr><td colspan="2">&nbsp;</td></tr>
            
        <?php 
		break;
	} 
} ?>
<!--</table>-->
<p class="submit">
<input name="save" type="submit" value="Save changes" />    
<input type="hidden" name="action" value="save" />
</p>
</form>
<form method="post">
<p class="submit">
<input name="reset" type="submit" value="Reset" />
<input type="hidden" name="action" value="reset" />
</p>
</form>
<?php
}add_action('admin_menu', 'mytheme_add_admin'); ?>
<?php function theme_init(){
	load_theme_textdomain('paranimage', get_template_directory() . '/languages');
}add_action ('init', 'theme_init');
?>
<?php
if ( function_exists('register_sidebar') ) {
	register_sidebar(array(
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<h3 class="widgettitle">',
		'after_title' => '</h3>',
	));
}
function custom_comment($comment, $args, $depth) {
       $GLOBALS['comment'] = $comment; ?>
<li <?php comment_class(); ?> id="comment-<?php comment_ID( ); ?>">
	<?php echo comment_reply_link(array('reply_text' => __('Reply', 'paranimage'), 'depth' => $depth, 'max_depth' => $args['max_depth']));  ?>
	<?php 
		$default_avatar = get_bloginfo('template_url').'/images/avatar.gif';
		echo get_avatar( $comment, 32, $default_avatar); ?>
	<?php comment_author_link() ?> <?php _e('says', 'paranimage'); ?>:
<?php if ($comment->comment_approved == '0') : //message if comment is held for moderation ?>
<em class="comment-tips"><?php _e('Your comment is awaiting moderation', 'paranimage'); ?>.</em>
<?php endif; ?>
<br />
<small class="commentmetadata">
<?php comment_date('l, F j, Y') ?> <?php _e('at', 'paranimage'); ?> <?php comment_date('G:i') ?><?php edit_comment_link( __('Edit', 'paranimage'),' &nbsp;|&nbsp; ',''); ?></small>
<br />
	<?php comment_text() ?>
<?php }  ?>
<?php function custom_pings($comment, $args, $depth) {
       $GLOBALS['comment'] = $comment; ?>
<li <?php comment_class(); ?> id="comment-<?php comment_ID( ); ?>">
     <?php comment_author_link() ?> - <small><?php comment_date('F j, Y') ?> <?php edit_comment_link( __('Edit', 'paranimage'),'<br /> &nbsp;|&nbsp; ',''); ?></small>
</li>
<?php } ?>
<?php function par_nextprev() { ?>
	<?php global $paged, $wp_query;
		$max_page = $wp_query->max_num_pages;
		if(is_single()) { ?>
		<span class="next" title="Next Post"><?php next_post_link('%link','%title',TRUE); ?></span>
		<a class="home" title="Return Home" href="<?php bloginfo('url'); ?>">Home</a>
		<span class="prev" title="Previous Post"><?php previous_post_link('%link','%title',TRUE); ?></span>
	<?php } else { ?>
		<span class="next" title="Previous Pages"><?php previous_posts_link('Prev'); ?></span>
		<a class="home" title="Return Home" href="<?php bloginfo('url'); ?>">Home</a>
		<span class="prev" title="Next Pages"><?php next_posts_link('Next'); ?></span>
	<?php } ?>
<?php } ?>